// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLStatement;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObjectImpl;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleExceptionStatement.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLStatement.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../../utils/listTran.h"

OracleExceptionStatement_Item::OracleExceptionStatement_Item()
{
  statements = std::make_shared<std::list<SQLStatement_ptr>>();
}

SQLExpr_ptr OracleExceptionStatement_Item::getWhen()
{
  return when;
}

void OracleExceptionStatement_Item::setWhen(SQLExpr_ptr when)
{
  this->when = when;
}

SQLStatement_list_ptr OracleExceptionStatement_Item::getStatements()
{
  return statements;
}

void OracleExceptionStatement_Item::setStatement(SQLStatement_ptr statement)
{
  if (statement != nullptr)
  {
    statement->setParent(SharedObject(OracleExceptionStatement_Item));
    this->statements->push_back(statement);
  }
}

// @Override
void OracleExceptionStatement_Item::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleExceptionStatement_Item)))
  {
    acceptChild(visitor, when);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLStatement, SQLObject>(statements);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(OracleExceptionStatement_Item));
}

SQLObject_ptr OracleExceptionStatement_Item::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleExceptionStatement_Item>(new OracleExceptionStatement_Item());
  std::shared_ptr<OracleExceptionStatement_Item> x = std::dynamic_pointer_cast<OracleExceptionStatement_Item>(clone_tmp);
  // OracleExceptionStatement_Item x = new OracleExceptionStatement_Item();
  if (when != nullptr)
  {
    x->setWhen(std::dynamic_pointer_cast<SQLExpr>(when->clone()));
  }
  for (SQLStatement_ptr stmt : *statements)
  {
    SQLStatement_ptr stmt2 = std::dynamic_pointer_cast<SQLStatement>(stmt->clone());
    stmt2->setParent(x);
    x->statements->push_back(stmt2);
  }
  return x;
}

OracleExceptionStatement::OracleExceptionStatement()
{
  items = std::make_shared<std::list<OracleExceptionStatement_Item_ptr>>();
}

OracleExceptionStatement_Item_list_ptr OracleExceptionStatement::getItems()
{
  return items;
}

void OracleExceptionStatement::addItem(OracleExceptionStatement_Item_ptr item)
{
  if (item != nullptr)
  {
    item->setParent(SharedObject(OracleExceptionStatement));
  }

  this->items->push_back(item);
}

// @Override
void OracleExceptionStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleExceptionStatement)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<OracleExceptionStatement_Item, SQLObject>(items);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(OracleExceptionStatement));
}

SQLObject_ptr OracleExceptionStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleExceptionStatement>(new OracleExceptionStatement());
  std::shared_ptr<OracleExceptionStatement> x = std::dynamic_pointer_cast<OracleExceptionStatement>(clone_tmp);
  // OracleExceptionStatement x = new OracleExceptionStatement();
  for (OracleExceptionStatement_Item_ptr item : *items)
  {
    OracleExceptionStatement_Item_ptr item2 = std::dynamic_pointer_cast<OracleExceptionStatement_Item>(item->clone());
    item2->setParent(x);
    x->items->push_back(item2);
  }
  return x;
}
